const express = require('express');
const app = express();
const adminModel = require('./db/model/adminModel');
require('./db')
app.use(express.json())
app.use(express.urlencoded())
app.post('/advAdmin',async function(req,res){
    const {
        adminName,
        password,
        regTime
    } = req.body
    // console.log(adminName,password,regTime);
    try {

        const findResult = await adminModel.findOne({
            adminName,
        })
        if (findResult) {
           return res.send({
                code: 10001,
                msg: "添加管理员-用户已经被注册",
                data: null
            })
        }
        await adminModel.create({
            adminName,
            password,
            regTime
        })
        res.send({
            code: 10000,
            msg: '添加管理员-添加成功',
            data: null
        })
    } catch (error) {
        res.send({
            code: 10002,
            msg: '添加管理员-服务端异常',
            data: null
        })
    }
})
app.listen(8000, () => {
    console.log('服务器部署成功。http://127.0.0.1:8000');
})